package com.atguigu.cloud.tool;/**
 * @Auter 李孝在
 * @Date 2024/11/18
 */

import com.baomidou.mybatisplus.core.toolkit.Assert;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @projectName: keshe
 * @package: com.atguigu.cloud.tool
 * @className: securityPasswordEncrypt
 * @author: Eric
 * @description: TODO
 * @date: 2024/11/18 11:22
 * @version: 1.0
 */
public class securityPasswordEncrypt {
    // 工作因子，默认值是10，最小值是4，最大值是31，值越大运算速度越慢
    private PasswordEncoder encoder = new BCryptPasswordEncoder(4);

    //加密
    public String Encrypt(String password){
        return encoder.encode(password);
    }

    //验证
    public void Verify(String password){

        String result = encoder.encode(password);
        //密码校验
        Assert.isTrue(encoder.matches(password, result), "密码不一致");

    }

}
